<template>
  <el-drawer
    custom-class="com-drawer"
    ref="drawerRef"
    v-bind="getBindValue"
    destroy-on-close
    lock-scroll
    with-header
    :size="dialogWidth"
    :title="title"
    :show-close="false"
    :fullscreen="fullscreen"
    :close-on-click-modal="false"
  >
    <template #header>
      <!-- <span class="drawer__icon">
        <el-icon v-if="showFullscreen" @click="toggleFull">
          <Minus v-if="fullscreen"/>
          <FullScreen v-else/>
        </el-icon>
      </span> -->
    </template>

    <!-- 弹窗内容 -->
    <div class="content__wrap">
      <slot></slot>
    </div>

    <template #footer>
      <slot name="footer"></slot>
    </template>
  </el-drawer>
</template>

<script setup name="Drawer">
/* eslint-disable */
import { ref, computed, unref, useAttrs } from 'vue'
import { useI18n } from 'vue-i18n'
const { t } = useI18n() // 中英文
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  dialogWidth: {
    type: String,
    default: '800px'
  },
  // 是否显示全屏按钮
  showFullscreen: {
    type: Boolean,
    default: true
  }
})

const fullscreen = ref(false)

const getBindValue = computed(() => {
  const delArr = ['showFullscreen']
  const attrs = useAttrs()
  const obj = { ...attrs, ...props }
  for (const key in obj) {
    if (delArr.indexOf(key) !== -1) {
      delete obj[key]
    }
  }
  return obj
})

function toggleFull() {
  fullscreen.value = !fullscreen.value
  // 全屏的时候需要重新定义left top
  if (fullscreen.value) {
    const dragDom = unref(dialogRef).$refs.dialogRef
    dragDom.style.cssText += `;left:0px;top:0px;`
  }
}
</script>
<style lang="scss">
.com-drawer {
  .el-drawer__title {
    font-size: 18px;
    font-weight: 500;
    color: #333333;
    line-height: 32px;
  }
  .drawer__button--wrap {
    position: fixed;
    top: 16px;
    right: 16px;
  }
}
</style>
<style lang="scss" scoped>
.drawer__icon {
  position: absolute;
  right: 45px;
  color: #909399;
  cursor: pointer;
  transition: color 0.2s;
  &:hover {
    color: var(--el-color-primary);
  }
}
</style>
